Page 94 - 2629_Devagiri_C-8
P. 94

Program 10 To Count the Number of Digits in a Number.


                      Program10.py
                   File  Edit  Format   Run    Options   Window    Help

                   num = int(input("Enter a number: "))
                   count = 0
                   while num > 0:
                       num = num // 10
                       count += 1
                   print("Total number of digits:", count)




                      Output

                   Enter a number: 56
                   Total number of digits: 2




                   Program 11    To print a right-angled triangle using the pattern of stars.
                                 *
                                 **
                                 ***
                                 ****
                                 *****

                      Program11.py                                                          Output

                   File  Edit  Format   Run    Options   Window    Help                  *
                                                                                         **
                   for i in range(1, 6):
                                                                                         ***
                       print("*" * i)
                                                                                         ****
                                                                                         *****




                   Program 12 To calculate and display the sum of numbers from 1 to 10.


                      Program12.py
                   File  Edit  Format   Run    Options   Window    Help

                   total = 0
                                                                                            Output
                   for i in range(1, 11):
                       total += i                                                        Sum of numbers from
                                                                                         1 to 10 is: 55
                   print("Sum of numbers from 1 to 10 is:", total)





                   92
                        Premium Edition-VIII
   89   90   91   92   93   94   95   96   97   98   99